package control;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import model.general.Util;

public class KeyEventGame extends KeyAdapter {
	private IControlGame control;
	private char stateGame;

	public KeyEventGame(IControlGame control) {
		this.control = control;
		System.out.println("key event game");
	}

	@Override
	public void keyPressed(KeyEvent e) {
		move(e);
		super.keyPressed(e);
	}

	public void move(KeyEvent e) {
		stateGame = control.getStateGame();

		if (e.getKeyCode() == KeyEvent.VK_LEFT) {
			control.moveBoatLeft();
		}
		if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
			control.moveBoatRight();
		}
		if (e.getKeyCode() == KeyEvent.VK_DOWN) {
			control.throwHook();
		}
		if (e.getKeyCode() == KeyEvent.VK_P) {
			control.pauseGame();
		}
		if (e.getKeyCode() == KeyEvent.VK_R && (stateGame == Util.PAUSE_STATE)
				|| (stateGame == Util.LOSE_STATE)) {
			control.resumeGame();
		}
		if (e.getKeyCode() == KeyEvent.VK_S) {
			control.startGame();
		}
		if (e.getKeyCode() == KeyEvent.VK_M) {
			control.changeStateMusic();
		}
		if (e.getKeyCode() == KeyEvent.VK_SPACE
				&& (stateGame == Util.LEVEL_UP_STATE || stateGame == Util.WON_STATE)) {
			control.nextGame();
			control.resumeGame();
		}
		if (e.getKeyCode() == KeyEvent.VK_H && stateGame == Util.WON_STATE) {
			control.heightScore();
		}

	}
}
